<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>系统用户 </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/admin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/style/admin.css" media="all">
</head>
<body>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>用户</cite></a>
        <a><cite>系统用户</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">系统用户列表</div>
                <div class="layui-card-body">
                    <div class="layui-btn-group user-table-btn" style="margin-bottom: 10px;">
                        <button class="layui-btn" data-type="getCheckData">批量禁用</button>
                        <button class="layui-btn" data-type="getCheckLength">批量恢复</button>
                        <button class="layui-btn layui-btn-danger" data-type="isAll">批量删除</button>
                    </div>

                    <table class="layui-hide" id="user-table" lay-filter="user-table"></table>

                    <script type="text/html" id="table-bar">
                        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
                        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<table class="layui-table" lay-skin="nob" id="viewuser" style="display: none;">
    <colgroup>
        <col width="100">
        <col>
    </colgroup>
    <tbody>
    <tr><td>账号 </td><td id="un"></td></tr>
    <tr><td>部门 </td><td id="up"></td></tr>
    <tr><td>当日下载 </td><td id="cd"></td></tr>
    <tr><td>全部下载 </td><td id="ad"></td></tr>
    </tbody>
</table>

<script src="/static/admin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function(){
        var table = layui.table
            ,admin = layui.admin;

        table.render({
            elem: '#user-table'
            ,url: '/admin/user/index.html'
            ,cols: [[
                {type:'checkbox', width:100,}
                ,{field:'id', title: 'ID', width:100, sort: true}
                ,{field:'username', width:300, title: '用户名'}
                ,{field:'bumen', title: '部门', width:200, sort: true}
                ,{field:'login_ip', title: '最后登录IP', width:200}
                ,{field:'create_at', title: '注册时间', width:200, sort: true}
                ,{field:'status', title: '状态', width:100, sort: true}
                ,{width:200, align:'center', toolbar: '#table-bar'}
            ]]
            ,page: true
        });

        //监听表格复选框选择
        table.on('checkbox(user-table)', function(obj){
            console.log(obj)
        });
        //监听工具条
        table.on('tool(user-table)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                //layer.msg('ID：'+ data.id + ' 的查看操作');
                $.get("{:url('admin/user/viewuser')}?uid="+data.id, function (res) {
                    if(res) {
                        $('#un').html(data.username);
                        $('#up').html(data.bumen);
                        $('#cd').html(res.cd);
                        $('#ad').html(res.ad);
                        layer.open({
                            type: 1
                            , title: '用户详细信息查看'
                            , area: ['400px', '250px']
                            , shade: 0
                            , maxmin: true
                            , offset: 'auto'
                            , content: $('#viewuser')
                            , zIndex: layer.zIndex //重点1
                            , success: function (layero) {
                                layer.setTop(layero); //重点2
                            }
                        });
                    }
                });
            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.alert('编辑行：<br>'+ JSON.stringify(data))
            }
        });

        var $ = layui.$, active = {
            getCheckData: function(){ //获取选中数据
                var checkStatus = table.checkStatus('user-table')
                    ,data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
            ,getCheckLength: function(){ //获取选中数目
                var checkStatus = table.checkStatus('user-table')
                    ,data = checkStatus.data;
                layer.msg('选中了：'+ data.length + ' 个');
            }
            ,isAll: function(){ //验证是否全选
                var checkStatus = table.checkStatus('user-table');
                layer.msg(checkStatus.isAll ? '全选': '未全选')
            }
        };

        $('.user-table-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>
</body>
</html>